#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;

int numberOfArithmeticSlices(vector<int>& nums) {
    int n = nums.size();
    vector<vector<int>> dp(n, vector<int>(n));

    unordered_map<long long, vector<int>> hash;
    for (int i = 0; i < n; i++)
        hash[nums[i]].push_back(i);

    int sum = 0;
    for (int j = 2; j < n; j++) {
        for (int i = 1; i < j; i++) {
            long long t = (long long)2 * nums[i] - nums[j];
            if (hash.count(t)) {
                for (auto k : hash[t]) {
                    if (k < i)
                        dp[i][j] += dp[k][i] + 1;
                }
            }
            sum += dp[i][j];
        }
    }
    return sum;
}

int main()
{
    vector<int>nums = { 2, 4, 6, 8, 10 };
    cout << numberOfArithmeticSlices(nums) << endl;
    return 0;
}